package main

import "fmt"

func main() {
	// s1 := []int{1, 2, 3}
	// fmt.Printf("s1 ==> %v ### %p\n", s1, &s1)
	// s2 := append(s1, 4)
	// fmt.Printf("s1 ==> %v ### %p\n", s1, &s1)
	// fmt.Printf("s2 ==> %v ### %p\n", s2, &s2)

	// s3 := make([]int, 3, 5)
	// fmt.Printf("s3 ==> %v ### %p\n", s3, &s3)
	// s4 := append(s3, 4)
	// fmt.Printf("s3 ==> %v ### %p\n", s3, &s3)
	// fmt.Printf("s4 ==> %v ### %p\n", s4, &s4)

	//1.声明切片
	var s1 []int
	if s1 == nil {
		fmt.Println("s1是空")
	} else {
		fmt.Println("s2不是空")
	}
	// 2.:=
	s2 := []int{}
	if s2 == nil {
		fmt.Println("s2 is nil")
	} else {
		fmt.Println("s2 is not nil")
	}
	// 3.make()
	var s3 []int = make([]int, 0)
	if s3 == nil {
		fmt.Println("s3 is nil")
	} else {
		fmt.Println("s3 is not nil")
	}
	fmt.Println(s1, s2, s3)
	// 4.初始化赋值
	var s4 []int = make([]int, 0, 0)
	fmt.Println(s4)
	s5 := []int{1, 2, 3}
	fmt.Println(s5)
	// 5.从数组切片
	arr := [5]int{1, 2, 3, 4, 5}
	var s6 []int
	// 前包后不包
	s6 = arr[1:4]
	fmt.Println(s6)
	s7 := arr[1:3:4]
	fmt.Printf("s6 len() ==> %d\n", len(s6))
	fmt.Printf("s6 cap() ==> %d\n", cap(s6))
	fmt.Printf("s7 len() ==> %d\n", len(s7))
	fmt.Printf("s7 cap() ==> %d\n", cap(s7))

	s10 := make([]int, 0, 5)
	fmt.Printf("%p\n", &s10)

	s11 := append(s10, 1)
	fmt.Printf("%p\n", &s11)

	fmt.Println(s10, s11)
	fmt.Printf("s10 ==> %p\n", &s10)
	fmt.Printf("s11 ==> %p\n", &s11)
	fmt.Println(cap(s10), cap(s11))

	fmt.Println("===================")
	s12 := arr[:3]

	fmt.Println(arr)
	fmt.Printf("arr ==> %p\n", &arr)
	fmt.Printf("arr[0] ==> %p\n", &arr[0])
	fmt.Printf("s12 ==> %p\n", &s12)

	s12[0] = 55
	s13 := append(s12, 33)
	fmt.Printf("s12 ==> %p\n", &s12)
	fmt.Printf("s13 ==> %p\n", &s13)
	fmt.Println(arr, s12, s13)

	fmt.Println("===================")
	data := [...]int{0, 1, 2, 3, 4, 10: 0}
	fmt.Println(data)

	s := data[:2:3]
	s[0] = 55
	s = append(s, 100, 200)
	fmt.Println(data, s)
	s[0] = 44
	fmt.Println(data, s)

	fmt.Println("===================")
	s20 := []int{1, 2, 3, 4}
	s21 := []int{11, 12, 13}
	fmt.Println(s20, s21)
	copy(s20, s21)
	fmt.Println(s20, s21)
	s22 := []int{1, 2, 3, 4}
	s23 := []int{11, 12, 13}
	copy(s23, s22)
	fmt.Println(s23, s22)

	fmt.Println("=======(resize)============")
	var a = []int{1, 3, 4, 5}
	fmt.Printf("slice a : %v , len(a) : %v\n", a, len(a))
	b := a[1:2]
	fmt.Printf("slice b : %v , len(b) : %v\n", b, len(b))
	c := b[0:3]
	fmt.Printf("slice c : %v , len(c) : %v\n", c, len(c))

	fmt.Println("===================")
	d := a
	fmt.Printf("%p\n%p\n", &a, &d)
}
